This is How it Started

I wanted to map data from the “Incarceration Trends” #tidytuesday project on a geographic map after being inspired by a more traditional graphical representation from lizwillow on GitHub. In addition to the clarity in the data vis, I also like to explore national and state-level data through comparing national metrics to the states I have lived in.

I ran into issues with the map packages I had used previously, so I got the idea to start with a new-to-me package as a way to help my brain detach from whatever it was that kept me from getting what I wanted out of old code I had used for a few specific purposes. I thought I could pay better attention to detail if I knew I was learning a whole new package.

Choose a Map Package

I chose usmap package because it includes capacity to map Alaska and Hawaii unlike some other map packages I have used before. Even though much of the mapping I do these days is centered on the state of Oregon, I think it’s good to practice a map package that has more than the contiguous 48. Download the usmap documentation at https://usmap.dev/.

Map Template

I start by practicing a blank / boundary-only map of the fifty (50) states of the U.S.A. The code for this is from the usmap documentation, but it’s good to start simple.

Mapping Included Data

Using area data contained in the usmap package:

More Data

I also wanted to map newer poverty rate data onto the county map using usmap package.

Documentation for 2019 poverty data from Small Area Income and Poverty Estimates (SAIPE) Program available here.

Expanding the Scale

Let’s see if it’s that easy when I scale it up to map county rates of poverty onto the entire U.S. map.

In the first attempt, I removed the labels argument, so it defaults to labels = FALSE. I removed the include = argument, so all fifty (50) states show up on the map, and I adjusted the plot labs, so I wouldn’t get confused. The result? I got a map that only has state outlines. Worse, it had all states the same saturation of grey fill.

In the second attempt, I filtered out the fips = 0, which is for the entire U.S. and filtered out the fips with “000” in attempt to remove all the state totals. That did a pretty good job, but I noticed there are several county-like polygons that got swept up in the removed data which resulted in some counties with grey fill rather than a data-scaled fill.

I got it in the third attempt where I only removed the the row where fips == 0.

Success! Well, success enough to move on to my originally intended data.

Original Endnote from 06/12/2021:

But I’m tired, so I’ll get to that next week. I would like to get to it tomorrow because I’m excited about it, but I am in the midst of a move, so I expect I will be pretty well occupied.

Advanced Mods

Labels

I am looking for a way to modify the in-map labels. I see in the usmap documentation that I can easily alter the text color of the labels (on states or on counties). I want to change the label font size and the label positioning, so the county labels no longer overlap severely enough to be unclear for anyone unfamiliar with Oregon counties. I also want a way to include/exclude subsets of labels. When I’m comparing a group of counties or states to the rest of the state or nation and am using a scale_fill option, I want to indicate the polygons of interest by labeling them and not the others.

Polygon Boundaries

I also want to highlight a subset of the county boundaries. This is for the same reason I want to include/exclude subsets of labels as mentioned above.

See the Code

The associated .Rmd file is available at https://github.com/RAAmodeo/r_examples/tree/master/usmap.